﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;//Please add references
namespace DAL
{
	/// <summary>
	/// 数据访问类:T_BaseExam
	/// </summary>
	public partial class T_BaseExam
	{
		public T_BaseExam()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(Model.T_BaseExam model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_BaseExam(");
			strSql.Append("ExamName,TypeCode,TypeName,AddDate,StartDate,EndDate,CountTime,RandomSubject,RandomItem,EvaluatorWayCode,EvaluatorWayName,IsMatchExam,ExamStatus,Executor,SubSource,Lock,Accept_Count,Bellow_Score,StartTime,Department,iszw,IsMnLx,IsXzKc)");
			strSql.Append(" values (");
			strSql.Append("@ExamName,@TypeCode,@TypeName,@AddDate,@StartDate,@EndDate,@CountTime,@RandomSubject,@RandomItem,@EvaluatorWayCode,@EvaluatorWayName,@IsMatchExam,@ExamStatus,@Executor,@SubSource,@Lock,@Accept_Count,@Bellow_Score,@StartTime,@Department,@iszw,@IsMnLx,@IsXzKc)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@ExamName", SqlDbType.NVarChar,50),
					new SqlParameter("@TypeCode", SqlDbType.Int,4),
					new SqlParameter("@TypeName", SqlDbType.VarChar,20),
					new SqlParameter("@AddDate", SqlDbType.Char,10),
					new SqlParameter("@StartDate", SqlDbType.Char,10),
					new SqlParameter("@EndDate", SqlDbType.Char,10),
					new SqlParameter("@CountTime", SqlDbType.Int,4),
					new SqlParameter("@RandomSubject", SqlDbType.Bit,1),
					new SqlParameter("@RandomItem", SqlDbType.Bit,1),
					new SqlParameter("@EvaluatorWayCode", SqlDbType.Int,4),
					new SqlParameter("@EvaluatorWayName", SqlDbType.NVarChar,50),
					new SqlParameter("@IsMatchExam", SqlDbType.Bit,1),
					new SqlParameter("@ExamStatus", SqlDbType.Bit,1),
					new SqlParameter("@Executor", SqlDbType.VarChar,20),
					new SqlParameter("@SubSource", SqlDbType.Int,4),
					new SqlParameter("@Lock", SqlDbType.Int,4),
					new SqlParameter("@Accept_Count", SqlDbType.Int,4),
					new SqlParameter("@Bellow_Score", SqlDbType.Int,4),
					new SqlParameter("@StartTime", SqlDbType.Char,10),
					new SqlParameter("@Department", SqlDbType.NVarChar,50),
					new SqlParameter("@iszw", SqlDbType.TinyInt,1),
					new SqlParameter("@IsMnLx", SqlDbType.TinyInt,1),
					new SqlParameter("@IsXzKc", SqlDbType.TinyInt,1)};
			parameters[0].Value = model.ExamName;
			parameters[1].Value = model.TypeCode;
			parameters[2].Value = model.TypeName;
			parameters[3].Value = model.AddDate;
			parameters[4].Value = model.StartDate;
			parameters[5].Value = model.EndDate;
			parameters[6].Value = model.CountTime;
			parameters[7].Value = model.RandomSubject;
			parameters[8].Value = model.RandomItem;
			parameters[9].Value = model.EvaluatorWayCode;
			parameters[10].Value = model.EvaluatorWayName;
			parameters[11].Value = model.IsMatchExam;
			parameters[12].Value = model.ExamStatus;
			parameters[13].Value = model.Executor;
			parameters[14].Value = model.SubSource;
			parameters[15].Value = model.Lock;
			parameters[16].Value = model.Accept_Count;
			parameters[17].Value = model.Bellow_Score;
			parameters[18].Value = model.StartTime;
			parameters[19].Value = model.Department;
			parameters[20].Value = model.iszw;
			parameters[21].Value = model.IsMnLx;
			parameters[22].Value = model.IsXzKc;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Model.T_BaseExam model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_BaseExam set ");
			strSql.Append("ExamName=@ExamName,");
			strSql.Append("TypeCode=@TypeCode,");
			strSql.Append("TypeName=@TypeName,");
			strSql.Append("AddDate=@AddDate,");
			strSql.Append("StartDate=@StartDate,");
			strSql.Append("EndDate=@EndDate,");
			strSql.Append("CountTime=@CountTime,");
			strSql.Append("RandomSubject=@RandomSubject,");
			strSql.Append("RandomItem=@RandomItem,");
			strSql.Append("EvaluatorWayCode=@EvaluatorWayCode,");
			strSql.Append("EvaluatorWayName=@EvaluatorWayName,");
			strSql.Append("IsMatchExam=@IsMatchExam,");
			strSql.Append("ExamStatus=@ExamStatus,");
			strSql.Append("Executor=@Executor,");
			strSql.Append("SubSource=@SubSource,");
			strSql.Append("Lock=@Lock,");
			strSql.Append("Accept_Count=@Accept_Count,");
			strSql.Append("Bellow_Score=@Bellow_Score,");
			strSql.Append("StartTime=@StartTime,");
			strSql.Append("Department=@Department,");
			strSql.Append("iszw=@iszw,");
			strSql.Append("IsMnLx=@IsMnLx,");
			strSql.Append("IsXzKc=@IsXzKc");
			strSql.Append(" where ExamId=@ExamId");
			SqlParameter[] parameters = {
					new SqlParameter("@ExamName", SqlDbType.NVarChar,50),
					new SqlParameter("@TypeCode", SqlDbType.Int,4),
					new SqlParameter("@TypeName", SqlDbType.VarChar,20),
					new SqlParameter("@AddDate", SqlDbType.Char,10),
					new SqlParameter("@StartDate", SqlDbType.Char,10),
					new SqlParameter("@EndDate", SqlDbType.Char,10),
					new SqlParameter("@CountTime", SqlDbType.Int,4),
					new SqlParameter("@RandomSubject", SqlDbType.Bit,1),
					new SqlParameter("@RandomItem", SqlDbType.Bit,1),
					new SqlParameter("@EvaluatorWayCode", SqlDbType.Int,4),
					new SqlParameter("@EvaluatorWayName", SqlDbType.NVarChar,50),
					new SqlParameter("@IsMatchExam", SqlDbType.Bit,1),
					new SqlParameter("@ExamStatus", SqlDbType.Bit,1),
					new SqlParameter("@Executor", SqlDbType.VarChar,20),
					new SqlParameter("@SubSource", SqlDbType.Int,4),
					new SqlParameter("@Lock", SqlDbType.Int,4),
					new SqlParameter("@Accept_Count", SqlDbType.Int,4),
					new SqlParameter("@Bellow_Score", SqlDbType.Int,4),
					new SqlParameter("@StartTime", SqlDbType.Char,10),
					new SqlParameter("@Department", SqlDbType.NVarChar,50),
					new SqlParameter("@iszw", SqlDbType.TinyInt,1),
					new SqlParameter("@IsMnLx", SqlDbType.TinyInt,1),
					new SqlParameter("@IsXzKc", SqlDbType.TinyInt,1),
					new SqlParameter("@ExamId", SqlDbType.Int,4)};
			parameters[0].Value = model.ExamName;
			parameters[1].Value = model.TypeCode;
			parameters[2].Value = model.TypeName;
			parameters[3].Value = model.AddDate;
			parameters[4].Value = model.StartDate;
			parameters[5].Value = model.EndDate;
			parameters[6].Value = model.CountTime;
			parameters[7].Value = model.RandomSubject;
			parameters[8].Value = model.RandomItem;
			parameters[9].Value = model.EvaluatorWayCode;
			parameters[10].Value = model.EvaluatorWayName;
			parameters[11].Value = model.IsMatchExam;
			parameters[12].Value = model.ExamStatus;
			parameters[13].Value = model.Executor;
			parameters[14].Value = model.SubSource;
			parameters[15].Value = model.Lock;
			parameters[16].Value = model.Accept_Count;
			parameters[17].Value = model.Bellow_Score;
			parameters[18].Value = model.StartTime;
			parameters[19].Value = model.Department;
			parameters[20].Value = model.iszw;
			parameters[21].Value = model.IsMnLx;
			parameters[22].Value = model.IsXzKc;
			parameters[23].Value = model.ExamId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ExamId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_BaseExam ");
			strSql.Append(" where ExamId=@ExamId");
			SqlParameter[] parameters = {
					new SqlParameter("@ExamId", SqlDbType.Int,4)
			};
			parameters[0].Value = ExamId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string ExamIdlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_BaseExam ");
			strSql.Append(" where ExamId in ("+ExamIdlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_BaseExam GetModel(int ExamId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ExamId,ExamName,TypeCode,TypeName,AddDate,StartDate,EndDate,CountTime,RandomSubject,RandomItem,EvaluatorWayCode,EvaluatorWayName,IsMatchExam,ExamStatus,Executor,SubSource,Lock,Accept_Count,Bellow_Score,StartTime,Department,iszw,IsMnLx,IsXzKc from T_BaseExam ");
			strSql.Append(" where ExamId=@ExamId");
			SqlParameter[] parameters = {
					new SqlParameter("@ExamId", SqlDbType.Int,4)
			};
			parameters[0].Value = ExamId;

			Model.T_BaseExam model=new Model.T_BaseExam();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_BaseExam DataRowToModel(DataRow row)
		{
			Model.T_BaseExam model=new Model.T_BaseExam();
			if (row != null)
			{
				if(row["ExamId"]!=null && row["ExamId"].ToString()!="")
				{
					model.ExamId=int.Parse(row["ExamId"].ToString());
				}
				if(row["ExamName"]!=null)
				{
					model.ExamName=row["ExamName"].ToString();
				}
				if(row["TypeCode"]!=null && row["TypeCode"].ToString()!="")
				{
					model.TypeCode=int.Parse(row["TypeCode"].ToString());
				}
				if(row["TypeName"]!=null)
				{
					model.TypeName=row["TypeName"].ToString();
				}
				if(row["AddDate"]!=null)
				{
					model.AddDate=row["AddDate"].ToString();
				}
				if(row["StartDate"]!=null)
				{
					model.StartDate=row["StartDate"].ToString();
				}
				if(row["EndDate"]!=null)
				{
					model.EndDate=row["EndDate"].ToString();
				}
				if(row["CountTime"]!=null && row["CountTime"].ToString()!="")
				{
					model.CountTime=int.Parse(row["CountTime"].ToString());
				}
				if(row["RandomSubject"]!=null && row["RandomSubject"].ToString()!="")
				{
					if((row["RandomSubject"].ToString()=="1")||(row["RandomSubject"].ToString().ToLower()=="true"))
					{
						model.RandomSubject=true;
					}
					else
					{
						model.RandomSubject=false;
					}
				}
				if(row["RandomItem"]!=null && row["RandomItem"].ToString()!="")
				{
					if((row["RandomItem"].ToString()=="1")||(row["RandomItem"].ToString().ToLower()=="true"))
					{
						model.RandomItem=true;
					}
					else
					{
						model.RandomItem=false;
					}
				}
				if(row["EvaluatorWayCode"]!=null && row["EvaluatorWayCode"].ToString()!="")
				{
					model.EvaluatorWayCode=int.Parse(row["EvaluatorWayCode"].ToString());
				}
				if(row["EvaluatorWayName"]!=null)
				{
					model.EvaluatorWayName=row["EvaluatorWayName"].ToString();
				}
				if(row["IsMatchExam"]!=null && row["IsMatchExam"].ToString()!="")
				{
					if((row["IsMatchExam"].ToString()=="1")||(row["IsMatchExam"].ToString().ToLower()=="true"))
					{
						model.IsMatchExam=true;
					}
					else
					{
						model.IsMatchExam=false;
					}
				}
				if(row["ExamStatus"]!=null && row["ExamStatus"].ToString()!="")
				{
					if((row["ExamStatus"].ToString()=="1")||(row["ExamStatus"].ToString().ToLower()=="true"))
					{
						model.ExamStatus=true;
					}
					else
					{
						model.ExamStatus=false;
					}
				}
				if(row["Executor"]!=null)
				{
					model.Executor=row["Executor"].ToString();
				}
				if(row["SubSource"]!=null && row["SubSource"].ToString()!="")
				{
					model.SubSource=int.Parse(row["SubSource"].ToString());
				}
				if(row["Lock"]!=null && row["Lock"].ToString()!="")
				{
					model.Lock=int.Parse(row["Lock"].ToString());
				}
				if(row["Accept_Count"]!=null && row["Accept_Count"].ToString()!="")
				{
					model.Accept_Count=int.Parse(row["Accept_Count"].ToString());
				}
				if(row["Bellow_Score"]!=null && row["Bellow_Score"].ToString()!="")
				{
					model.Bellow_Score=int.Parse(row["Bellow_Score"].ToString());
				}
				if(row["StartTime"]!=null)
				{
					model.StartTime=row["StartTime"].ToString();
				}
				if(row["Department"]!=null)
				{
					model.Department=row["Department"].ToString();
				}
				if(row["iszw"]!=null && row["iszw"].ToString()!="")
				{
					model.iszw=int.Parse(row["iszw"].ToString());
				}
				if(row["IsMnLx"]!=null && row["IsMnLx"].ToString()!="")
				{
					model.IsMnLx=int.Parse(row["IsMnLx"].ToString());
				}
				if(row["IsXzKc"]!=null && row["IsXzKc"].ToString()!="")
				{
					model.IsXzKc=int.Parse(row["IsXzKc"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ExamId,ExamName,TypeCode,TypeName,AddDate,StartDate,EndDate,CountTime,RandomSubject,RandomItem,EvaluatorWayCode,EvaluatorWayName,IsMatchExam,ExamStatus,Executor,SubSource,Lock,Accept_Count,Bellow_Score,StartTime,Department,iszw,IsMnLx,IsXzKc ");
			strSql.Append(" FROM T_BaseExam ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ExamId,ExamName,TypeCode,TypeName,AddDate,StartDate,EndDate,CountTime,RandomSubject,RandomItem,EvaluatorWayCode,EvaluatorWayName,IsMatchExam,ExamStatus,Executor,SubSource,Lock,Accept_Count,Bellow_Score,StartTime,Department,iszw,IsMnLx,IsXzKc ");
			strSql.Append(" FROM T_BaseExam ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_BaseExam ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ExamId desc");
			}
			strSql.Append(")AS Row, T.*  from T_BaseExam T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "T_BaseExam";
			parameters[1].Value = "ExamId";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

